
package guoan.web.webCustomer;

import guoan.core.dto.DataGridModel;
import guoan.core.dto.PageResponse;
import guoan.core.dto.RestResponse;
import guoan.domain.CoachConfig;
import guoan.domain.CoachItem;
import guoan.domain.Train;
import guoan.service.CoachConfigService;
import guoan.service.CoachService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.base.Preconditions;

@Controller
@RequestMapping("/webCustomer/coach")
public class CoachController {
    protected final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private CoachService coachService;

    @Autowired
    private CoachConfigService coachConfigService;

    /**
     * @Title：index
     * @Description: 考试的预约结果界面
     * @author Administrator
     * @date 2015年4月21日 上午9:23:40
     * @param examId 考试ID
     * @param model 界面model
     * @return String
     */
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String index(){
    	coachService.removeLast();
        return "/webCustomer/coach/index";

    }

    /**
     * @Title：data
     * @Description: TODO
     * @author Administrator
     * @date 2015年4月21日 上午9:25:37
     * @param dataGridModel
     * @param type
     * @return PageResponse<ExamItem>
     */
    @RequestMapping(value = "data", method = RequestMethod.POST)
    @ResponseBody
    public PageResponse<CoachItem> data(DataGridModel dataGridModel,String key){
        return coachService.page(dataGridModel,key);
    }

    @RequestMapping(value = "coachConfig", method = RequestMethod.GET)
    public String coachConfig(Model model){
        CoachConfig cc = coachConfigService.findCoachConfig();
        model.addAttribute("cc", cc);
        return "/webCustomer/coach/coachConfig";
    }

    @RequestMapping(value = "coachConfig", method = RequestMethod.POST)
    @ResponseBody
    public RestResponse<Boolean> update(CoachConfig coachConfig){
        Preconditions.checkNotNull(coachConfig, "参数错误");
        return coachConfigService.update(coachConfig);
    }
}
